import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;


 class File extends Icon { 

    String filePath = "C:\\test2.txt";
    String filePath2 = "C:\\test3.txt";
    BufferedReader br;
    String line = "";
    String read="";
    ArrayList<String> storeWordList = new ArrayList<String>();

    List<String> tem = new LinkedList<String>();
    List<String> temp = new LinkedList<String>();
    List<String> temps = new LinkedList<String>();
    String String1[]= String2();
    String String[]=S();
    String Name[]=Names();

	public File(int n) {
		super();
	}
	ListOfObjects Obj=new ListOfObjects();
	
     Icon icon =new Icon();
     
ProblemWithoutMain p = new ProblemWithoutMain();
public String[] S(){
    try {
        FileInputStream fstream = new FileInputStream("test2.txt");
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        //Read File Line By Line
        boolean found = false;
        while ((strLine = br.readLine()) != null) {
        	
        	String [] tokens = strLine.split("\\s+");
        	for(int i=0; i < tokens.length; i++)
        	{
                if(tokens[i].contains("objects"))
                {
                	found = true;
                }
                if(found)
                	break;
            	storeWordList.add(tokens[i]);
        	}
        }
        //Close the input stream

        in.close();
        

    } catch (Exception e) {//Catch exception if any
        System.err.println( e.getMessage());
    }
    String s []= storeWordList.toArray(new String[0]);

    return s;
}



public String[] String2(){
    try {
    	
        br = new BufferedReader(new FileReader(filePath));
        try {
        	temps.add("(:init ");
            while((line = br.readLine()) != null)
            {	
             	read=br.readLine();
            	String[] words = line.split(" ");
            	 for (String word : words) {
          	 if(word.equals("(:init")){
          	
           		 while((read = br.readLine()) != null){
            	  temps.add(read);
           		 
               	 }
           	    } 
          	  }
            }
          
            br.close();
           
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
		String[] tempsArray = temps.toArray(new String[0]);

	return tempsArray;
}



public void WriteInProblem() throws FileNotFoundException, UnsupportedEncodingException{
	

	PrintWriter writer = new PrintWriter("Problem.txt", "UTF-8");
	for(int i=0 ; i<String.length; i++){
		writer.println(String[i] );
	}
	writer.println("(:objects" );

	for(int i=1 ; i<Name.length; i++){
	writer.println(   Obj.retrieve(i)+ " ;; taken " +" " + Name[i] );
	}
	for(int i=0;i<String1.length;i++){
		writer.println(String1[i]);
	}

	
	writer.close();
}

}
	

